package com.leyou.upload.config;

import com.aliyun.oss.OSS;
import com.aliyun.oss.OSSClient;
import com.aliyun.oss.OSSClientBuilder;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

@Configuration
public class OSSConfig {

    // 注入方式一
    /*@Autowired
    private OSSProperties prop;*/

    @Bean               // 注入方式二： 直接写在方法参数中
    public OSS ossClient(OSSProperties prop){
                // 这个已经过期了
        //OSSClient client = new OSSClient(endpoint, accessId, accessKey);
        // 换下面这个工厂来来创建
        return new OSSClientBuilder()
                .build(prop.getEndpoint(), prop.getAccessKeyId(), prop.getAccessKeySecret());
    }
}
